#include <iostream>
#include "vector"
#include "deque"
#include "algorithm"
#include "ctime"

using namespace std;

/*
 * 创建5个选手，放入vector中，遍历vector，对每一位选手进行打分，将10个评委的分数存到deque中
 * sort算法对deque中元素进行排序，去除最高和最低分，deque遍历，累加总分，获取平均分
 */

class Person{
public:
    string p_name;
    deque<int> score;
    Person(string name){
        this->p_name = name;
    }
};

void printArray(vector<Person> v){
    for (vector<Person>::iterator it= v.begin();  it != v.end(); ++it) {
        for (int i = 0; i < it->score.size(); ++i) {
            cout << it->score[i]<< " ";
        }
        cout << endl;
    }
}

void test01(){
    Person p1("A");
    Person p2("B");
    Person p3("C");
    Person p4("D");
    Person p5("E");
    vector<Person> v;
    v.push_back(p1);
    v.push_back(p2);
    v.push_back(p3);
    v.push_back(p4);
    v.push_back(p5);

    srand((unsigned)time(nullptr));

    for (vector<Person>::iterator it = v.begin(); it != v.end() ; ++it) {
        for (int i = 0; i < 10; ++i) {
            it->score.push_back(rand() % 100);
        }
    }
    cout << "选手分数" << endl;
    printArray(v);

    for (vector<Person>::iterator it=v.begin(); it!= v.end();++it) {
        sort(it->score.begin(), it->score.end());
    }
    cout << "排序后" << endl;
    printArray(v);

    // 删除一个最低分，删除一个最高分
    for (vector<Person>::iterator it= v.begin(); it != v.end(); ++it) {
        it->score.pop_back();
        it->score.pop_front();
    }

    cout << "删除极值后" << endl;
    printArray(v);

    for (vector<Person>::iterator it= v.begin(); it!= v.end(); ++it) {
        int sum = 0;
        for (int i = 0; i < it->score.size(); ++i) {
            sum += it->score[i];
        }
        cout << "得分:" << sum / 8.0 << endl;
    }
}

int main() {
    test01();

    return 0;
}
